﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="../style.css">
<link href="../tablecloth/tablecloth.css" rel="stylesheet" type="text/css" media="screen" />
<script type="text/javascript" src="../tablecloth/tablecloth.js"></script>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body>

<?php	

	include("../inc/joomlaInt_admin.php");
	include("../inc/inc_configuration.php");

if ($jUser==0)
{
	echo "Bitte zuerst einloggen!";
}
else
{	
	
	$q="SELECT gid FROM $tbl_users WHERE id=$jUser";
					$qe=mysql_query($q);
					$qeo=mysql_fetch_object($qe);
					
					$gid=$qeo->gid;
					
					if ($gid!=$admingroup)
					{
						echo "Du bist kein Admin!";
						break;
					}
	
	echo "<table>
			<tr>
				<th>Id</th>
				<th>Liga</th>
				<th>Spieltag</th>
				<th>Heim</th>
				<th></th>
				<th>Gast</th>
				<th>frei?</th>
				<th>Wertung</th>
			</tr>";
	
	$mq=	"SELECT 		m1.id AS mId, 
							m1.homeG AS hG,
							m1.guestG AS gG,
							m1.playdate AS pd,
							m1.matchday AS spieltag, 
							m1.homeT AS hTi, 
							m1.guestT AS gTi, 
							t1.name AS hTn, 
							t2.name AS gTn,
							m1.homeC AS hC,
							m1.guestC AS gC,
							m1.free AS free,
							l.name AS liganame
							
						FROM $tbl_matches m1, $tbl_teams t1, $tbl_teams t2, $tbl_leagues l
						
						WHERE
						m1.homeT=t1.id AND
						m1.guestT=t2.id AND 
						m1.leagueId=l.id AND
						m1.free=1
						ORDER BY liganame ASC, mId ASC
					";
	
	$mqe=mysql_query($mq);
				
	while ($row=mysql_fetch_object($mqe))
	{
		$mId=$row->mId;
		$tHi=$row->hTi;
		$tGi=$row->gTi;
		$tHn=$row->hTn;
		$tGn=$row->gTn;
		$hG=$row->hG;
		$gG=$row->gG;
		$playdate=$row->pd;
		$spieltag=$row->spieltag;
		$liganame=$row->liganame;
		
		$free=$row->free;
		
		$playdate=date("d.m.y - H:i",$playdate);
		
		if ($free>=3)
		{
			$cHi=$row->hC;
			$cGi=$row->gC;
			
			$uHSql="	SELECT username FROM $tbl_combinations c, $tbl_users u
							WHERE
							(c.id=$cHi) AND
							(c.userId=u.id)";
			$uGSql="	SELECT username FROM $tbl_combinations c, $tbl_users u
							WHERE
							(c.id=$cGi) AND
							(c.userId=u.id)";
							
			$uHq = mysql_query($uHSql);
			$uGq = mysql_query($uGSql);
			
			$uHnq = mysql_fetch_object($uHq);
			$uHn = $uHnq->username;
			
			$uGnq = mysql_fetch_object($uGq);
			$uGn = $uGnq->username;
			
		}
		else
		{
			//Combinations suchen
			$uHSql="	SELECT username AS uHn, c.id AS hC FROM $tbl_combinations c, $tbl_users u
							WHERE
							(c.teamId=$tHi) AND
							(c.active=1) AND
							(c.userId=u.id)";
			$uGSql="	SELECT username AS uGn, c.id AS gC FROM $tbl_combinations c, $tbl_users u
					WHERE
					(c.teamId=$tGi) AND
					(c.active=1) AND
					(c.userId=u.id)";
					
			$uHq = mysql_query($uHSql);
			$uGq = mysql_query($uGSql);

			
			$cH = mySQL_num_rows($uHq);
			$cG = mySQL_num_rows($uGq);
			
			if ($cH == 1)
			{
				$uHnq = mysql_fetch_object($uHq);
				$uHn = $uHnq->uHn;
				
			}
			else
			{
				$uHn = "(-)";
			}
			
			if ($cG == 1)
			{
				$uGnq = mysql_fetch_object($uGq);
				$uGn = $uGnq->uGn;
				
			}
			else
			{
				$uGn = "(-)";
			}
		}
		
		
		
		if ($hG=="" OR $hG=="NULL")
		{
			$hG="-";
		}
		if ($gG=="" OR $gG=="NULL")
		{
			$gG="-";
		}
		
		if ($playdate=="")
		{
			$playdate="-";
		}
		
		
		echo "	<tr>
					<td>$mId</td>
					<td>$liganame</td>
					<td>$spieltag</td>
					<td>$tHn<br>$uHn</td>
					<td>:</td>
					<td>$tGn<br>$uGn</td>
					<td>$free</td>
					<td><a href='spiel_werten.php?id=$mId'>Werten</a></td>
				</tr>";	
	}
	
	echo "<tr><th colspan='12'></th></tr></table>";
	
	echo "<br><br><center><a href='../lima.php' class='button zurueck'>Zurück</a>";
}	
?>

</body>
</html>